﻿using PSDLib.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PSDClient
{
    public partial class FrmDevice : Form
    {
        public List<dl_download_device> DownloadDeviceList { get; set; }
        public dl_download_device SelectedDevice { get; set; }
        public FrmDevice()
        {
            InitializeComponent();

            this.Shown += FrmDevice_Shown;
        }

        private void FrmDevice_Shown(object sender, EventArgs e)
        {
            if (DownloadDeviceList != null)
            {
                this.listView1.Items.Clear();

                for (int i = 0; i < DownloadDeviceList.Count; i++)
                {
                    var device = DownloadDeviceList[i];
                    string conn_type = "";

                    if (device.device_connect_type == 0)
                    {
                        conn_type = "USB";
                    }
                    else
                    {
                        conn_type = "网络:" + device.device_ip;
                    }
                    this.listView1.Items.Add(new ListViewItem(new string[] {
                       (i+1).ToString(),
                       device.device_name,
                       conn_type,
                       device.data_path,
                       device.state==0 ? "未使用" : ("已使用：" +device.state)
                    })).Tag = device;
                }
            }
        }

        private void btnSelect_Click(object sender, EventArgs e)
        {
            if (this.listView1.SelectedItems.Count > 0)
            {
                SelectedDevice = (dl_download_device)this.listView1.SelectedItems[0].Tag;
            }

            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            SelectedDevice = null;
            this.Close();
        }
    }
}
